import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public class TreeMapDemo1 {
    public static void main(String[] args) {
        TreeMap<Integer,String> treeMap = new TreeMap<>();
        treeMap.put(1,"关羽");
        treeMap.put(2,"张飞");
        treeMap.put(3,"赵云");
        treeMap.put(4,"黄忠");
        treeMap.put(5,"马超");

        //遍历TreeMap

        //获取entrySet来遍历TreeMap
        for (Map.Entry<Integer, String> entry : treeMap.entrySet()) {
            System.out.println("键值对的为："+entry.getKey() + "键值对的值为："+entry.getValue());
        }

        //一条华丽的分割线
        System.out.println("*****************************");

        //获取keySet来遍历TreeMap的key
        for (Integer i : treeMap.keySet()) {
            System.out.println("键值对的键为"+i);
        }

        System.out.println("*****************************");

        //获取Values来遍历TreeMap的value
        for (String value : treeMap.values()) {
            System.out.println("键值对的值为"+value);
        }

        System.out.println("*****************************");

        //利用Map.entrySet自带的迭代器进行遍历
        for (Map.Entry<Integer, String> integerStringEntry : treeMap.entrySet()) {
            System.out.println(integerStringEntry);
        }

    }
}
